package com.itheima.lianxi;

import java.util.Scanner;

/**
 * 需求：键盘录入一个字符串，统计该字符串中大写字母字符，小写字母字符，数字字符出现的次数(不考虑其他字符)
 */
public class Demo3 {
    public static void main(String[] args) {
        //键盘录入字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串:");
        String str = sc.next();
        //设计bigSum\smallSum\numSum分别统计大写字符,小写字符,数字字符的数量
        int bigSum = 0;
        int smallSum = 0;
        int numSum = 0;
        //将字符串转变为字符数组
        char[] chars = str.toCharArray();
        //遍历字符数组
        for (int i = 0; i < chars.length; i++) {
            //chars[i]
            //比较'a'到'z''0'到'9''A'到'Z'记录数据
            if (chars[i] >= 'a' && chars[i] <= 'z'){
                smallSum++;
            }else if (chars[i] >= 'A' && chars[i] <= 'Z'){
                bigSum++;
            }else if (chars[i] >= '0' && chars[i] <= '9'){
                numSum++;
            }
        }
        //分别输出每种字符的数量
        System.out.println("大写字符:"+bigSum);
        System.out.println("小写字符:"+smallSum);
        System.out.println("数字字符:"+numSum);

    }
}
